AbstractEventCommandHandler.getUser   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
1
import { ISchoolRepository } from 'src/Domain/School/Repository/ISchoolRepository';
2
import { SchoolNotFoundException } from 'src/Domain/School/Exception/SchoolNotFoundException';
3
import { IUserRepository } from 'src/Domain/User/Repository/IUserRepository';
4
import { UserNotFoundException } from 'src/Domain/User/Exception/UserNotFoundException';
5
import { User } from 'src/Domain/User/User.entity';
6
import { School } from 'src/Domain/School/School.entity';
7
8
export abstract class AbstractEventCommandHandler {
9
  constructor(
10
    private readonly schoolRepository: ISchoolRepository,
11
    private readonly userRepository: IUserRepository
12
  ) {}
13
14
  protected async getUser(userId: string): Promise<User> {
15
    const user = await this.userRepository.findOneById(userId);
16
    if (!user) {
17
      throw new UserNotFoundException();
18
    }
19
20
    return user;
21
  }
22
23
  protected async getSchool(schoolId: string): Promise<School> {
24
    const school = await this.schoolRepository.findOneById(schoolId);
25
    if (!school) {
26
      throw new SchoolNotFoundException();
27
    }
28
29
    return school;
30
  }
31
}
32